package com.wangsd.web.shop.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangsd.common.basicbean.MyController;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.shop.entity.CouponOrder;
import com.wangsd.web.shop.entity.Member;
import com.wangsd.web.shop.service.CouponOrderService;
import com.wangsd.web.shop.service.MemberService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "代金券")
@RestController
@RequestMapping("/shop/member")
@Slf4j
public class MemberController extends MyController {

    @Autowired
    private MemberService service;

    @ApiOperation(value = "分页查询列表")
    @PostMapping("/selectPage")
    public Object selectPage(@ApiParam(value = "当前第几页", required = true) @RequestParam("pageNum") Integer pageNum,
                             @ApiParam(value = "每页结果集大小", required = true) @RequestParam("pageSize") Integer pageSize,
                             @ApiParam(value = "排序字段") @RequestParam(required = false) String sortField,
                             @ApiParam(value = "排序方式") @RequestParam(required = false) String sortOrder,
                             Member queryObj) {
        Page page = PageHelper.startPage(pageNum, pageSize);
        SysUser loginUser = this.getUserInfo();
        List<Member> list = service.selectPage(queryObj, loginUser.getParentCode(), sortField, sortOrder);
        return Result.success(getPageInfo(page, list));
    }

    @ApiOperation(value = "补录积分")
    @PostMapping("/additionalIntegral")
    public Object additionalIntegral(@ApiParam(value = "会员id", required = true) @RequestParam Long id,
                                     @ApiParam(value = "积分", required = true) @RequestParam Integer integral,
                                     @ApiParam(value = "描述", required = true) @RequestParam String description) {
        service.additionalIntegral(id, integral, description);
        return Result.success();
    }
}
